// components/read/ReadComponent.js
const computedBehavior = require("miniprogram-computed").behavior;
Component({

  behaviors: [computedBehavior],
  /**
   * 组件的属性列表
   */
  properties: {
    currentIndex: {
      type: Number,
      value: 0
    },
    content: {
      type: String,
      value:""
    },
    readPage:{
      type:Number,
      value:0
    },
    options: {
      type:Object,
      value:{
        offsetFontSize: "0",
        color: "#151515",
        backgroundColor: "#fff",
        model: 0
      }
    }
  },

 


  /**
   * 组件的初始数据
   */
  data: {
    init:true,
    title: '',
    contentList:[]
  },
  computed: {
    readContent(data) {
      // let style = 'style="';
      // for (const key in data.options) {
      //   style += `${key}:${data.options[key]};`
      // }
      // style += '"';
      let temp = "";
      temp = data.content.replaceAll(/<h1.*?>.*?<\/h1>/g,"").replaceAll(/[^>]<\/p>/g,"</p><br/>").replaceAll(/<p><\/p>|<div><\/div>/g,"");
      
      return temp;
    },
    fontSize(data){
      console.log(data.options.offsetFontSize+40+'rpx');
      return data.options.offsetFontSize+40+'rpx';
    }
  },
  observers:{
    "readContent":function(readContent){
      let str = this.data.content;
      let temp = "";
      temp = str.match(/<h1.*?>.*?<\/h1>/g);
      temp = temp ? temp[0] : "";
      temp = temp.match(/(?:>)(.*?)(?:<)/g);
      temp = temp ? temp[1].replaceAll(/>|</g,"") : "";
      let map = [];
      11;
      str = str.replaceAll(/<h1.*?>.*?<\/h1>/g,"").replaceAll(/[^>]<\/p>/g,"</p><br/>").replaceAll(/<p><\/p>|<div><\/div>/g,"");
      map = str.match(/(?:<p>).*?<\/p>/g);
      this.setData({
        title:temp,
        contentList:map
      })
    },
    "readPage":function(readPage){
      console.log(readPage,'1111111111111');
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // sloveContent(content, options) {
    //   let temp = "";
    //   let style = 'style="';
    //   for (const key in options) {
    //     style += `${key}:${options[key]};`
    //   }
    //   style += '"';
    //   let str = content;
    //   temp = str.match(/<h1.*?>.*?<\/h1>/g);
    //   temp = temp ? temp[0] : "";
    //   // console.log(content);
    //   console.log(temp, "temp");
    //   111111;
    //   return content;
    // },
    // getContent(text) {
    //   const reg = /<p>.*<\/p>/;
    //   let array = text.match(reg);
    //   console.log(array);
    //   return;
    //   this.setData({
    //     contents: array.replaceAll("</p>", "</p>#").split("#")
    //   })
    //   console.log(this.data.contents, 'sdada');
    // }
  }
})